let portalContext;
$(function(){
    portalContext = top.$("#content");
});
function openTable(url,title,active){
    let tabPanel=portalContext;
    if(tabPanel){
        title=title.substr(0,8);
        let pCfg={
            title:title,
            fit:true,
            content:'<iframe scrolling="yes"  style="display:block;width: 100%;height: 100%"  frameborder="0" src="'+url+'"></iframe>',
            closable:true
        };
        let tab=tabPanel.tabs("getTab",title);
        if(tab){
            tabPanel.tabs("select",title);
            /*
            tabPanel.tabs('update', {
                tab: tab,
                options: pCfg
            });

             */
            return;
        }
        tabPanel.tabs("add",pCfg);
        if(typeof active=="undefined" || active){
        }
    }
}
let _databaseTypes=[{'label':'MYSQL','value':'MYSQL'},{'label':'ORACLE','value':'ORACLE'}];
let _frontEnds=[{'label':'EASYUI','value':'EASYUI'}];
let _jdbcTypes=[{'text':'DECIMAL','value':'DECIMAL'},{'text':'VARCHAR','value':'VARCHAR'},{'text':'CHAR','value':'CHAR'},{'text':'INT','value':'INT'},{'text':'BIGINT','value':'BIGINT'},{'text':'TINYINT','value':'TINYINT'},{'text':'SMALLINT','value':'SMALLINT'},{'text':'DATE','value':'DATE'}
    ,{'text':'OBJECT','value':'OBJECT'},{'text':'LIST','value':'LIST'}];
let _dateFormat =[{'text':'无','value':''},{'text':'yyyy-MM-dd','value':'yyyy-MM-dd'},{'text':'yyyy-MM-dd HH:mm:ss','value':'yyyy-MM-dd HH:mm:ss'}]
function commCallBack(__mainDialog,__mainGrid){
    return function(data){
        if(true == data || "success" == data.code  ){
            $.messager.alert('提示', '操作成功！');
            if (__mainDialog) $(__mainDialog).dialog('close');
            if(__mainGrid)  $(__mainGrid).datagrid("reload");
        }else{
            $.messager.alert('提示', data.message);
        }
    }
}

function myPostJsonConfirm(msg,url,data,fn){
    $.messager.confirm("提示", msg, function (r) {
        if (r) {
            $.messager.progress({ title:'请等待', msg:'正在执行...' });
            $.ajax({
                type: 'post',
                dataType:"json",
                contentType : 'application/json;charset=utf-8', //设置请求头信息
                url: url,
                data: data,
                success: function (data) {
                    $.messager.progress('close');
                    fn(data);
                },
                error: function (msg) {
                    $.messager.progress('close');
                    $.messager.alert('提示', msg)
                }

            });

        }
    });

}

function trueFalseFmt(v){

    if(v==='true' || v == true){
        return '<span style="color: #3c8b3c">是</span>';
    }else{
        return '<span style="color: #d9534f">否</span>';
    }
}


function formatToHump(v){
    return v.toLowerCase().replace(/\_(\w)/g, (_, letter) => letter.toUpperCase())
}
function initJdbcType(comboboxId){
    myPostAjaxJson("getjDBCTypes",{},function(data){
        let rows = data.data;
        let _rows=[];

        rows.forEach(function(p){
            _rows.push({"id":p,"text":p});
        })
        $(comboboxId).combobox("loadData",_rows);
    })

}

function myPostAjaxJson(url,data,fn){
    $.ajax({
        type: 'post',
        dataType:"json",
        contentType : 'application/json;charset=utf-8', //设置请求头信息
        url: url,
        data: data,
        success: function (data) {
            fn(data);
        },
        error: function (msg) {
            $.messager.alert('提示', msg)
        }
    });

}

let javaTypes = [
    {value:'BigDecimal',text:'BigDecimal'},
    {value:'String',text:'String'},
    {value:'Long',text:'Long'},
    {value:'Integer',text:'Integer'},
    {value:'Date',text:'Date'}
];
let _queryTypes =[{value:'eq',text:'eq'},{value:'like',text:'like'},{value:'gt',text:'gt'},{value:'lt',text:'lt'}]


function includeTableWin(url){
    $.ajax({
        url:url,
        type:"GET",
        dataType:"html",
        success:function(result){
            $.parser.parse($("body").append(result));
        }
    })
}
function _saveLocal(formId,key){
    var data =  $(formId).serializeJson();
    localStorage.setItem(key , JSON.stringify(data));
}
function _getLocal(formId,key){
     let obj = JSON.parse(localStorage.getItem(key));
     setTimeout(function(){  $(formId).form("load", obj);},200)

}